package com.she.iiicoursecenter.view.tab1;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;

import com.she.iiicoursecenter.R;
import com.she.iiicoursecenter.activity.tab1_infomation.Tab1_CourseSet;
import com.she.iiicoursecenter.activity.tab1_infomation.Tab1_MainActivity;
import com.she.iiicoursecenter.adapter.Tab1_MainAdapter;
import com.she.iiicoursecenter.bean.CourseSetBundleBean;
import com.she.iiicoursecenter.bean.ViewChageDataBean;
import com.she.iiicoursecenter.event.connect.bean.GetItemListBean;
import com.she.iiicoursecenter.view.template.CustomizedView;

public class Tab1_MainView extends CustomizedView implements OnClickListener {
	//
	
	// test only!!!!!
//	private Button	mbtnGo;
	private ListView mListView;
	private Tab1_MainAdapter mTab1_Adapter;
	private List<GetItemListBean> date;

	public Tab1_MainView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		init();
	}

	private void init(){
		//
		LayoutInflater inflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.tab1_main, this, true);
		//
		
		// test only!!!!
//		mbtnGo = (Button)this.findViewById(R.id.btn_goto);
//		mbtnGo.setOnClickListener(new OnClickListener(){
//			public void onClick(View v) {
//				Message msg = Tab1_MainView.this.getApp().mChangeViewHandler.obtainMessage();
//				msg.what 	= Tab1_MainView.this.getApp().MSG_WHAT_CHANGEVIEW;
//				CourseSetBundleBean bundleBean 	= new CourseSetBundleBean("test1", "test2", "test3");
//				ViewChageDataBean   dataBean 	= new ViewChageDataBean(Tab1_MainActivity.class, Tab1_CourseSet.class, bundleBean);
//				msg.obj							= dataBean;
//				Tab1_MainView.this.getApp().mChangeViewHandler.sendMessage(msg);
//				
//			}});
		
		date = Tab1_MainView.this.getApp().getItemListBeanData();
		mTab1_Adapter = new Tab1_MainAdapter(getContext(), date);
		mListView = (ListView) this.findViewById(R.id.tv_listview);
		mListView.setAdapter(mTab1_Adapter);
		mListView.setDivider(new ColorDrawable(Color.TRANSPARENT));// 去除listview分隔線
		mListView.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				// TODO Auto-generated method stub
				getApp().fadein = true;
				Message msg = Tab1_MainView.this.getApp().mChangeViewHandler.obtainMessage();
				msg.what 	= Tab1_MainView.this.getApp().MSG_WHAT_CHANGEVIEW;
				CourseSetBundleBean bundleBean 	= new CourseSetBundleBean(date.get(arg2).getName(), date.get(arg2).getItemId());
				ViewChageDataBean   dataBean 	= new ViewChageDataBean(Tab1_MainActivity.class, Tab1_CourseSet.class, bundleBean);
				msg.obj							= dataBean;
				Tab1_MainView.this.getApp().mChangeViewHandler.sendMessage(msg);
				getApp().setItemName(date.get(arg2).getName());
				getApp().itemListColorCount = arg2;
			}
		});
	}
	
	public void onClick(View v) {
		// TODO Auto-generated method stub

	}
	
	public void notifyAdapter(){
		mTab1_Adapter.notifyDataSetChanged();
	}
		
}
